//
//  BaseApi.m
//  Main
//
//  Created by wangbaoping on 2022/4/14.
//

#import "BaseApi.h"
#import <NSObject+YYModel.h>
#import "ResponseModel.h"

@interface BaseApi()

@property(nonatomic,strong) ResponseModel * responseModel;
@end

@implementation BaseApi

-(void)startReqeust {
    [self startWithCompletionBlockWithSuccess:^(__kindof YTKBaseRequest * _Nonnull request) {
        self->_responseModel = [ResponseModel yy_modelWithJSON:request.responseObject];
        [self.apiDalegate onApiSuccess:self->_responseModel.data];
    } failure:^(__kindof YTKBaseRequest * _Nonnull request) {
        self->_responseModel = [[ResponseModel alloc] init];
        NSString *statusCode = [NSString stringWithFormat:@"%ld",(long)request.error.code];
        self->_responseModel.code = statusCode;
        self->_responseModel.msg = request.error.localizedDescription;
        if(self.apiDalegate){
            [self.apiDalegate onApiFailed:self->_responseModel];
        }
    }];
    
}

@end



